package com.tbit.main.pojo;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @author LMY
 * @create 2022-04-12 14:25
 */
public class FenToYuanForRMB extends JsonSerializer<Integer> {

    private static final BigDecimal DIVIDENUM = new BigDecimal(100);

    private static final String DEFAULT_VALUE = "0";

    /*@Override
    public void serialize(Integer integer, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String yuan = Objects.isNull(integer) ? DEFAULT_VALUE : new BigDecimal(integer).divide(DIVIDENUM).toString();
        jsonGenerator.writeString(yuan);
    }*/
    private DecimalFormat df = new DecimalFormat("#0.00");

    public FenToYuanForRMB() {
    }

    @Override
    public void serialize(Integer value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeString(this.df.format(value / 100));
    }

}
